package com.zrrd.mq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author WanJl
 * @version 1.0
 * @title FanoutConfig
 * @description
 * @create 2024/7/19
 */
@Configuration
public class FanoutConfig {
    /**
     * 声明交换机
     * @return Fanout类型交换机
     */
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("wanjl.fanout");
    }

    /**
     * 创建第1个队列
     * @return
     */
    @Bean
    public Queue fanoutQueue01(){
        return new Queue("fanout.queue01");
    }

    /**
     * 绑定第1个队列和交换机
     * @param fanoutQueue01
     * @param fanoutExchange
     * @return
     */
    @Bean
    public Binding fanoutBinding01(Queue fanoutQueue01,FanoutExchange fanoutExchange){
        //创建绑定关系，将fanoutQueue01队列和fanoutExchange交换机绑定到一起
        return BindingBuilder.bind(fanoutQueue01).to(fanoutExchange);
    }

    /**
     * 创建第2个队列
     * @return
     */
    @Bean
    public Queue fanoutQueue02(){
        return new Queue("fanout.queue02");
    }

    /**
     * 绑定第2个队列和交换机
     * @param fanoutQueue02
     * @param fanoutExchange
     * @return
     */
    @Bean
    public Binding fanoutBinding02(Queue fanoutQueue02,FanoutExchange fanoutExchange){
        //创建绑定关系，将fanoutQueue01队列和fanoutExchange交换机绑定到一起
        return BindingBuilder.bind(fanoutQueue02).to(fanoutExchange);
    }
}
